package priv.utrix.micro.implement;

import cn.hutool.core.util.StrUtil;
import com.google.common.base.Preconditions;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;
import priv.utrix.micro.constant.ResultCode;
import priv.utrix.micro.dubbo.RedisTokenDubbo;
import priv.utrix.micro.utils.RedisUtil;

/**
 * @author utrix
 * @date 2020/12/14
 */
@DubboService
@RequiredArgsConstructor
public class RedisTokenDubboService implements RedisTokenDubbo {

    final RedisUtil redisUtil;

    @Override
    public String getToken(String jti) {
        Preconditions.checkState(StrUtil.isNotBlank(jti), "The incoming jti parameter is empty");
        String token = redisUtil.strGet(jti);
        Preconditions.checkState(StrUtil.isNotBlank(token), ResultCode.TOKEN_INVALID_OR_EXPIRED);

        return token;
    }
}
